package com.ztjava.develop.service;

import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.Page;
import com.ztjava.core.base.BaseService;
import com.ztjava.core.client.Client;
import com.ztjava.develop.model.autocode.AutocodeComponent;
import com.ztjava.develop.model.autocode.AutocodeModel;
import com.ztjava.develop.model.autocode.AutocodePlugin;


public class AutocodeService extends BaseService{
	/***
	 * modelList
	 * @param component_id
	 * @return
	 */
	public List<AutocodeModel> getModelList(Integer component_id){
		return  AutocodeModel.dao.find("select * from "+AutocodeModel.tablename+" where component_id=? order by id asc",component_id);
	}
	/***
	 * model分页
	 * @param pageNumber
	 * @param pageSize
	 * @param whereSql
	 * @param orderby
	 * @param params
	 * @return
	 */
	public Page<AutocodeModel> getModelPage(Client client,Map<String,String[]> paramMap){

		String[][] params = new String[][]{
				new String[]{"component_id",eq,"component_id"},
				new String[]{"name",like,"name"},
				new String[]{"code",like,"code"}
		};
		Page<AutocodeModel> pd = AutocodeModel.dao.paginate(
				getParaToInt(paramMap, client.getPageNumber(), 1),
				getParaToInt(paramMap, client.getPageSize(), 20),
				"select *","from "+AutocodeModel.tablename
				+ " where 1=1 "
				+ whereSql(paramMap,params)
				+ orderby(client,paramMap)
				,whereParam(paramMap,params));
		changeBasedata(pd.getList(),new String[]{"list_type","DEVELOP_AUTOCODE_MODEL_LISTTYPE"});
		return pd;
	}
	
	public Page<AutocodePlugin> getPluginPage(Client client,Map<String,String[]> paramMap){
		String[][] params = new String[][]{
				new String[]{"name",like,"name"}
				,new String[]{"code",like,"code"}	
		};
		Page<AutocodePlugin> pd = AutocodePlugin.dao.paginate(
				getParaToInt(paramMap, client.getPageNumber(), 1),
				getParaToInt(paramMap, client.getPageSize(), 20),
				"select *","from "+AutocodePlugin.tablename+" where 1=1 "
				+ whereSql(paramMap,params)
				+ orderby(client,paramMap),
				whereParam(paramMap,params));
		return pd;
	}
	
	public Page<AutocodeComponent> getComponentPage(Client client,Map<String,String[]> paramMap){
		String[][] params = new String[][]{
				new String[]{"plugin_id",eq,"plugin_id"},
				new String[]{"name",like,"name"}
				,new String[]{"code",like,"code"}
		};
		Page<AutocodeComponent> pd = AutocodeComponent.dao.paginate(
				getParaToInt(paramMap, client.getPageNumber(), 1),
				getParaToInt(paramMap, client.getPageSize(), 20),
				"select *","from "+AutocodeComponent.tablename+" where 1=1 "
				+ whereSql(paramMap,params)
				+ orderby(client,paramMap),
				whereParam(paramMap,params));
		return pd;
	}
}
